﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Strongkeep.Model.Util
{
	/// <summary>
	/// 
	/// </summary>
	public static class Dice
	{
		/// <summary>
		/// 
		/// </summary>
		/// <param name="die"></param>
		/// <returns></returns>
		public static int Roll(int die)
		{
			Random random = new Random();
			return random.Next(1, die);
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="die"></param>
		/// <param name="quantity"></param>
		/// <returns></returns>
		public static int[] Roll(int die, int quantity)
		{
			int[] result = new int[quantity];
			for (int i = 0; i < quantity; i++) {
				result[i] = Roll(die);
			}
			return result;
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="die"></param>
		/// <param name="minimum"></param>
		/// <returns></returns>
		public static int RollMinimum(int die, int minimum)
		{
			if (minimum >= die) {
				return die;
			}
			Random random = new Random();
			return random.Next(minimum > 1 ? minimum : 1, die);
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="die"></param>
		/// <param name="minimum"></param>
		/// <returns></returns>
		public static int[] RollMinimum(int die, int minimum, int quantity)
		{
			int[] result = new int[quantity];
			for (int i = 0; i < quantity; i++) {
				result[i] = RollMinimum(die, minimum);
			}
			return result;
		}

		///// <summary>
		///// 
		///// </summary>
		///// <param name="die"></param>
		///// <param name="quantity"></param>
		///// <returns></returns>
		//public static IEnumerator<int> Roll(int die, int quantity)
		//{
		//    while (quantity-- > 0) { 
		//        yield return Roll(die);
		//    }
		//}

		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		public static int d4()
		{
			return Roll(4);
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="quantity"></param>
		/// <returns></returns>
		public static int[] d4(int quantity)
		{
			return Roll(4, quantity);
		}

		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		public static int d6()
		{
			return Roll(6);
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="quantity"></param>
		/// <returns></returns>
		public static int[] d6(int quantity)
		{
			return Roll(6, quantity);
		}

		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		public static int d8()
		{
			return Roll(8);
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="quantity"></param>
		/// <returns></returns>
		public static int[] d8(int quantity)
		{
			return Roll(8, quantity);
		}

		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		public static int d10()
		{
			return Roll(10);
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="quantity"></param>
		/// <returns></returns>
		public static int[] d10(int quantity)
		{
			return Roll(10, quantity);
		}

		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		public static int d12()
		{
			return Roll(12);
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="quantity"></param>
		/// <returns></returns>
		public static int[] d12(int quantity)
		{
			return Roll(12, quantity);
		}

		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		public static int d20()
		{
			return Roll(20);
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="quantity"></param>
		/// <returns></returns>
		public static int[] d20(int quantity)
		{
			return Roll(20, quantity);
		}

		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		public static int d100()
		{
			return Roll(100);
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="quantity"></param>
		/// <returns></returns>
		public static int[] d100(int quantity)
		{
			return Roll(100, quantity);
		}
	}
}
